<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="../scripts/jquery/jquery-1.7.1.js"></script>
    <link href="../style/authority/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="../style/authority/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../scripts/authority/commonAll.js"></script>
    <link rel="stylesheet" href="../style/bootstrap.min.css"/>
    <script type="text/javascript" src="../scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
    <script type="text/javascript" src="../scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <link rel="stylesheet" type="text/css" href="../style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
    <script type="text/javascript" src="../scripts/artDialog/artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../scripts/jquery.js"></script>
    <script type="text/javascript" src="../scripts/bootstrap.js"></script>
    <title>审计机构</title>
    <script type="text/javascript">
        function js_subordinate(id) {
            if (id != null && id != "") {
                $.ajax({
                    type: "GET",
                    url: "/AuditManagement/AjaxFindSubordinate",
                    dataType: 'json',
                    data: {"id": id},
                    async: false,
                    success: function (data) {
                        var html = '';
                        var superior = data.superior;
                        for (var i = 0; i < superior.length; i++) {
                            html += '<tr><td>' + superior[i].auditname + '</td>' +
                                '<td>' + superior[i].code + '</td></tr>';
                        }
                        $(".xiaji").empty();
                        $(".xiaji").append(html);
                    }
                });
            }
        }

        /**
         * 刷新当前页
         */
        function js_Again() {
            location.reload();
        }

        $(function () {
            //给全选的复选框添加事件
            $("#all").click(function () {
                // this 全选的复选框
                var userids = this.checked;
                //获取name=box的复选框 遍历输出复选框
                $("input[name=box]").each(function () {
                    this.checked = userids;
                });
            });

            //给name=box的复选框绑定单击事件
            $("input[name=box]").click(function () {
                //获取选中复选框长度
                var length = $("input[name=box]:checked").length;
                //未选中的长度
                var len = $("input[name=box]").length;
                if (length == len) {
                    $("#all").get(0).checked = true;
                } else {
                    $("#all").get(0).checked = false;
                }
            });

        });

        function js_insert() {
            var obj = document.getElementsByName("box");

            var flag = false;

            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    flag = true;
                    break;
                }
            }

            $("#js_insert").attr('data-toggle', 'modal');
            $("#js_insert").attr('data-target', '#insert');

            if (!flag) {
                alert("请选择审计机构！！！");
                $("#js_insert").removeAttr("data-toggle");
                $("#js_insert").removeAttr("data-target");
            }

            var check_val = [];
            for (var k in obj) {
                if (obj[k].checked) {
                    check_val.push(obj[k].value);
                }
            }

            if (check_val.length > 1) {
                alert("暂时只支持单个添加！！！");
                $("#js_insert").removeAttr("data-toggle");
                $("#js_insert").removeAttr("data-target");
            }

            if (check_val.length == 1) {
                $.ajax({
                    type: "GET",
                    url: "/AuditManagement/AjaxById",
                    dataType: 'json',
                    data: {"id": check_val.toString()},
                    async: false,
                    success: function (data) {
                        $("#name").val(data.byId.auditname);
                        $("#superior").val(data.byId.id);
                    }
                });

            }

        }

        function addOrganization() {
            var superior = $("#superior").val();
            var name = $("#name").val();
            var auditname = $("#auditname").val();
            var code = $("#code").val();

            function showErrorMess(ms) {
                $("#hint").html(ms);
            }

            if (superior == null || superior == '') {
                showErrorMess("系统异常！！！");
                return false;
            }
            if (name == null || name == '') {
                showErrorMess("系统异常！！！");
                return false;
            }
            if (auditname == null || auditname == '') {
                showErrorMess("名称不能为空！！！");
                return false;
            }
            if (code == null || code == '') {
                showErrorMess("代码不能为空！！！");
                return false;
            }
            return true;
        }

        function updateOrganization() {
            var id = $("#id").val();
            var code2 = $("#code2").val();
            var auditname2 = $("#auditname2").val();

            function showErrorMess(ms) {
                $("#hintUpdate").html(ms);
            }

            if (id == null || id == '') {
                showErrorMess("系统异常！！！");
                return false;
            }
            if (auditname2 == null || auditname2 == '') {
                showErrorMess("名称不能为空！！！");
                return false;
            }
            if (code2 == null || code2 == '') {
                showErrorMess("代码不能为空！！！");
                return false;
            }
            return true;
        }

        function delete_audit() {
            var obj = document.getElementsByName("box");

            var flag = false;

            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    flag = true;
                    break;
                }
            }

            if (!flag) {
                alert("请选择要删除的机构！");
            }

            var check_val = [];
            for (var k in obj) {
                if (obj[k].checked) {
                    check_val.push(obj[k].value);
                }
            }
            if (check_val.length > 0) {
                if (confirm("您确定要删除吗？")) {
                    $.ajax({
                        type: "GET",
                        traditional: true,//阻止深度序列化
                        url: "/AuditManagement/BatchRemove",
                        dataType: 'json',
                        data: {"ids": check_val},
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        success: function (feedback) {
                            if (feedback == true) {
                                location.reload(true);
                            }
                        }
                    });
                }
            }
        }

        function js_update() {

            var obj = document.getElementsByName("box");

            var flag = false;

            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    flag = true;
                    break;
                }
            }

            $("#updateA").attr('data-toggle', 'modal');
            $("#updateA").attr('data-target', '#update');

            if (!flag) {
                alert("请选择要修改的审计机构！！！");
                $("#updateA").removeAttr("data-toggle");
                $("#updateA").removeAttr("data-target");
            }

            var check_val = [];
            for (var k in obj) {
                if (obj[k].checked) {
                    check_val.push(obj[k].value);
                }
            }

            if (check_val.length > 1) {
                alert("暂时只支持单个修改！！！");
                $("#updateA").removeAttr("data-toggle");
                $("#updateA").removeAttr("data-target");
            }

            if (check_val.length == 1) {
                $.ajax({
                    type: "GET",
                    url: "/AuditManagement/AjaxById",
                    dataType: 'json',
                    data: {"id": check_val.toString()},
                    async: false,
                    success: function (data) {
                        $("#auditname2").val(data.byId.auditname);
                        $("#code2").val(data.byId.code);
                        $("#id").val(data.byId.id);
                    }
                });

            }

        }
    </script>
    <style>
        .alt td {
            background: black !important;
        }

        li {
            list-style-type: none;
        }
    </style>
</head>

<body>
<div id="container">
    <div class="ui_content">
        <div class="ui_text_indent">
            <div id="box_border">
                <div id="box_top"><span class="glyphicon glyphicon-user"></span>&nbsp;审计机构</div>
                <div id="box_bottom" style="background-color: #CCCCCC;">
                    <a href="#" id="js_insert" onclick="js_insert()">
                        <span class="glyphicon glyphicon-plus" style="color: #00B83F;"></span> 增加
                    </a>&nbsp;&nbsp;
                    <a href="#" onclick="delete_audit()">
                        <span class="glyphicon glyphicon-remove" style="color:red;"></span> 删除
                    </a>&nbsp;&nbsp;
                    <a href="#" onclick="js_update()" id="updateA">
                        <span class="glyphicon glyphicon-pencil" style="color: #02397F;"></span> 编辑
                    </a>&nbsp;&nbsp;
                    <a href="#" onclick="js_unsteady()">
                        <input type="hidden" id="unsteady" name="unsteady" value="OK">
                        <span class="glyphicon glyphicon-ok" style="color:#00B83F;;"></span> 分配管理机构
                    </a>
                    <a href="#" onclick="js_Again()">
                        <span class="glyphicon glyphicon-repeat" style="color:#000000;;"></span> 刷新
                    </a>
                </div>

            </div>
            <div class="box_bottom">
                <table class="table table-striped table-hover table-condensed">
                    <tr>
                        <th class="text-center" width="60px">
                            <input type="checkbox" id="all"/>
                        </th>
                        <th width="60%"><b>名称</b></th>
                        <th width="40%"><b>代码</b></th>
                    </tr>
                    <tr th:each="institution : ${institutionAll}" th:Object="${institution}">
                        <td>
                            <input type="checkbox" name="box" th:value="*{auditInstitution2.id}"/>
                        </td>
                        <td>
                            <a href="#" th:onclick="'javascript:js_subordinate(\''+ *{auditInstitution2.id}+'\')'">
                                <span th:text="*{auditInstitution2.auditname}"></span>
                            </a>
                            <span th:if="*{auditInstitution2.id} neq *{auditInstitution2.superior}"
                                  th:text="'（'+*{auditInstitution.auditname}+'）'">
                                </span>
                        </td>
                        <td th:text="*{auditInstitution2.code}"></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <br>
    <div class="ui_content" style="">
        <div class="ui_tb">
            &nbsp;&nbsp;&nbsp;&nbsp;
            <b>管理被审计机构</b>
            <span class="glyphicon glyphicon-arrow-down"></span>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50%" class="text-center">名称</th>
                    <th width="50%" class="text-center">代码</th>
                </tr>
                </thead>
                <tbody class="xiaji">

                </tbody>
            </table>
        </div>
    </div>
</div>
<!--增加的模态框-->
<div class="modal fade" id="insert">
    <div class="modal-dialog">
        <div class="modal-content" style="width: 450px;">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">×</button>
                <p>
                    <span style="font-size:16px; font-weight:normal">增加审计机构</span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span id="hint" style="color: red"></span>
                </p>
            </div>
            <form action="/AuditManagement/save" method="post" onSubmit="return addOrganization(this)">
                <div class="media-body container">
                    <br>
                    <table class="table table-condensed col-md-12">
                        <tr valign="middle" align="center">
                            <td>上级</td>
                            <td>
                                <input type="hidden" id="superior" name="superior" value="">
                                <input type="text" id="name" value="" readonly="readonly"/>
                            </td>
                        </tr>
                        <tr valign="middle" align="center">
                            <td>代码:</td>
                            <td><input type="text" id="code" name="code"/></td>
                        </tr>
                        <tr valign="middle" align="center">
                            <td>名称:</td>
                            <td><input type="text" id="auditname" name="auditname"/></td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-info btn-block">确定</button>
                    <input type="button" class="btn btn-warning btn-block" data-dismiss="modal" value="取消"/>
                </div>
            </form>
        </div>
    </div>
</div>
<!--结束-->
<!--修改的模态框-->
<div class="modal fade" id="update">
    <div class="modal-dialog">
        <div class="modal-content" style="width: 450px;">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">×</button>
                <p>
                    <span style="font-size:16px; font-weight:normal">修改审计机构</span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span id="hintUpdate" style="color: red"></span>
                </p>
            </div>
            <form action="/AuditManagement/batchUpdate" method="post" onSubmit="return updateOrganization(this)">
                <div class="media-body container">
                    <br>
                    <table class="table table-condensed col-md-12">
                        <tr valign="middle" align="center">
                            <td>代码:</td>
                            <td>
                                <input type="hidden" id="id" name="id" value="">
                                <input type="text" id="code2" name="code"/>
                            </td>
                        </tr>
                        <tr valign="middle" align="center">
                            <td>名称:</td>
                            <td><input type="text" id="auditname2" name="auditname"/></td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-info btn-block">确定</button>
                    <input type="button" class="btn btn-warning btn-block" data-dismiss="modal" value="取消"/>
                </div>
            </form>
        </div>
    </div>
</div>
<!--结束-->
</body>
</html>